<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="数据日期">
              <j-date placeholder="请选择数据日期" v-model="queryParam.sjrq"></j-date>
            </a-form-item>
          </a-col>
          &nbsp;&nbsp;&nbsp;
          <a-button type="danger" @click="searchQuery" icon="search">查询</a-button>
          <a-button type="danger" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button  @click="SubmitReturn " type="primary" icon="audit" v-has="'bbzt:submitBack'" >提交打回</a-button> -->
      <!-- <a-button type="danger" @click="searchQuery" icon="search">查询</a-button>
      <a-button type="danger" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> -->

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;" >
        <i class="anticon anticon-info-circle ant-alert-icon"></i>  <a>批量校验：{{jyInfo}}</a>
        <a style="margin-left: 24px;font-weight: 600" @click="showResult" v-show="isShowResult">查看校验结果</a>
        <a style="margin-left: 24px;font-weight: 600" @click="isResult=false">关闭</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: 1000,y:340}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a> -->
          <a @click="handleCheck(record)" :disabled='record.commitStatus == 3'>校验</a>
          <a-divider type="vertical" />
          <a @click="handleCheckResult(record)" >下载校验结果</a>
          <!--
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
          -->
        </span>
        <!-- <a slot="action" slot-scope="text" href="javascript:;">action</a> -->
      </a-table>
    </div>

<!--    <llbb-report-status-modal ref="modalForm" @ok="modalFormOk"></llbb-report-status-modal>-->

    <j-modal
      :visible.sync="modal.visible"
      :width="600"
      :title="modal.title"
      :fullscreen.sync="modal.fullscreen"
      :switchFullscreen="modal.switchFullscreen"
    >

      <template v-for="(i,k) in dataList">
        <p :key="k">{{i}}</p>
      </template>

    </j-modal>
    <j-modal
      :visible.sync="jmodal.visible"
      :width="600"
      :title="jmodal.title"
      :fullscreen.sync="jmodal.fullscreen"
      :switchFullscreen="jmodal.switchFullscreen"
      @cancel="handleCancel"
      >
      <a-textarea
        v-model="jmodal.reason"
        placeholder="请输入退回原因"
        maxLength="2000"
        :auto-size="{ minRows: 6, maxRows: 12}"
      />
    </j-modal>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {getAction, httpAction,downFile} from '@/api/manage'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import { mapGetters } from 'vuex'

  export default {
    name: 'ReportStatusList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JSelectDepart,
    },
    data () {
      return {
        interval:0,
        isShowResult:false,
        isResult:false,
        jyInfo:'',
        modal: {
          title: '信息提示',
          visible: false,
          fullscreen: false,
          switchFullscreen: false,
        },
        jmodal: {
          title: '信息提示',
          visible: false,
          fullscreen: false,
          switchFullscreen: false,
          ids:'',
          reason:'',
        },
        dataList:[],
        description: '报表状态表管理页面',
        disableMixinCreated:true,
        // 表头
        columns: [

        ],
        url: {
          list: "/reportstatus/llbbReportStatus/list",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      let depart = this.userInfo().username

        this.columns =  [
          {
            title: '选项',
            dataIndex: '',
            key:'rowIndex',
            width:50,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          /* {
             title:'法人名称',
             align:"center",
             dataIndex: 'bankNoCd_dictText'
           },*/
          {
            title:'数据日期',
            align:"center",
            width:100,
            dataIndex: 'sjrq'
          },
          // {
          //   title:'报表名称',
          //   align:"center",
          //   ellipsis: true,
          //   width:200,
          //   dataIndex: 'reportId_dictText'
          // },
          // {
          //   title:'数据状态',
          //   align:"center",
          //   width:100,
          //   dataIndex: 'dataStatus_dictText'
          // },
          {
            title:'校验状态',
            align:"center",
            width:100,
            dataIndex: 'verifyStatus_dictText'
          },

          {
            title:'提交状态',
            align:"center",
            width:100,
            dataIndex: 'commitStatus_dictText'
          },
          {
            title:'提交人',
            align:"center",
            width:90,
            dataIndex: 'createBy_dictText',
          },
          {
            title:'提交时间',
            align:"center",
            width:160,
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ]
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      show (record) {
        this.visible=true;
        this.queryParam.reportId = record;
        this.loadData();
      },
      searchReset(){
        //重置
        this.queryParam = {reportId:this.queryParam.reportId};
        this.loadData(1);
      },
      ...mapGetters(["nickname", "avatar","userInfo"]),
      handleCheck(record){
        //校验
        let checkUrl = "/verificationresult/llbbVerificationResult/reportDataCheck";
        //let checkParam = {"reportCode":record.reportId,"sjrq":record.sjrq,"type":false};
        let checkParam = {id:record.id};
        var that = this;
        this.$confirm({
          title: "提示",
          content: "是否开始校验?",
          onOk: function () {
            that.loading = true;
            getAction(checkUrl, checkParam).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      },
      handleCheckResult(record){
        //下载校验结果
        let fileName = "校验结果表";
        let downloadUrl = '/verificationresult/llbbVerificationResult/exportXls';
        let downloadParam = {"sjrq":record.sjrq,"reportCode":record.reportId};
        downFile(downloadUrl,downloadParam).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return;
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xls')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        });
      },
      handleCancel(){
        this.jmodal.visible=false;
      },
      showResult(){
        this.modal.visible=true;
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'bankNoCd',text:'法人标识'})
        fieldList.push({type:'string',value:'devideCls',text:'权限划分类别。按固定依据划分数据权限：1-角色2-机构3-用户'})
        fieldList.push({type:'string',value:'bankCode',text:'分支机构编码'})
        fieldList.push({type:'string',value:'reportId',text:'报表记录id'})
        fieldList.push({type:'string',value:'dataStatus',text:'数据状态。1-未生成2-已生成有误3-已生成成功'})
        fieldList.push({type:'string',value:'verifyStatus',text:'校验状态。1-未校验2-已校验有误3-已校验无误'})
        fieldList.push({type:'string',value:'commitStatus',text:'提交状态。1-未提交2-已打回3-已提交'})
        fieldList.push({type:'string',value:'auditStatus',text:'审核状态。1-未审核2-审核打回3-审核通过'})
        this.superFieldList = fieldList
      },
      SubmitReturn() {
        if (!this.url.SubmitReturn) {
          this.$message.error("请设置url.Batchcheck属性!")
          return;
        }
        if (this.selectionRows.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectionRows.length; a++) {
            ids += this.selectionRows[a].id + ",";
            if (this.selectionRows[a].commitStatus != "3") {
              this.$message.warning('未提交数据不能打回！');
              return;
            }
          }
          const that = this;
          that.jmodal.visible=true;
          that.jmodal.ids=ids;
        }
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>